package com.jmemoir.base.validation.controller;

import com.jmemoir.base.common.dto.Result;
import com.jmemoir.base.validation.dto.UserDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 测试控制层
 *
 * @author Tellsea
 * @date 2023/8/2
 */
@Validated
@RestController
@RequestMapping("/baseValidationTest")
public class BaseValidationTestController {

    @GetMapping("/userName")
    public Result<Void> validation(@NotEmpty(message = "用户名不能为空") String userName,
                                   @NotEmpty(message = "昵称不能为空") String nickName) {
        return Result.success("测试成功");
    }

    @GetMapping("/validation")
    public Result<UserDTO> validation(@Valid UserDTO userDTO) {
        return Result.success("测试成功", userDTO);
    }
}